package util;

/**
 * 字符工具类
 * @desc:
 *
 * @className: StringUtils.java
 * @author: fuchen
 * @date: 2020年10月26日
 */
public class ParseUtils {
	/**                                       数字相关                                      */
	public static boolean isLetter(char ch) {
		return (ch >= 'a' && ch <= 'z') || (ch >='A' && ch <= 'Z') || ch == '_';
	}
	
	public static boolean isDigit(char ch) {
		//Character.isDigit(c);
		return ch >= '0' && ch <= '9';
	}
	

	/**                                       操作数相关                                      */

	public static boolean isOps(char ch) {
		char[] chs = new char[] {'+', '-', '/', '%', '*', '!', '=', '<', '>'};
		for(char c : chs) {
			if (c == ch) return true;
		}
		return false;
	}
	
	
	public static boolean isOps(char[] ch) {
		if (ch.length <= 0 || ch.length > 2) return false;
		if (ch.length == 1) return isOps(ch[0]); 
		else {
			if(isOps(ch[0])) {
				if (ch[0] == ch[1] 
						&& ch[1] != '/' 
						&& ch[1] != '%' 
						&& ch[1] != '*') return true;
				if (ch[1] == '=') return true;
			}
		}
		return false;
	}

	/**                                       界符相关                                      */
	//双界符
	public static boolean isWordEnds(char ch) {
	   return '[' == ch || ']' == ch
			   || '(' == ch || ')' == ch
			   || '{' == ch || '}' == ch;
	}
	
	//单界符
	public static boolean isWordEnd(char ch) {
		return ch == ';' || ch == ',' || ch == ':';
	}
	
	//单词的终结符
	public static boolean isEnd(char ch) {
		return (isOps(ch) 
				|| isWordEnd(ch)
				|| isWordEnds(ch));
	}
	
	//当前行结束符
	public static boolean isCurLineOfEnd(char ch) {
		return ch == ' ' || ch == '\t' ;
	}
	
	//换行结束符
	public static boolean isLineChaneOfEnd(char ch) {
		return ch == '\r' || ch == '\n' ;
	}
	
	

	public static boolean isEmpty(String str) {
		return str == null || str.length() == 0;
	}
	
	
	
}
